﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using NLBS.Entity;
using NLBS.Data;
using System.Web.UI;

namespace NLBS
{
   public class GlobalData
    {

       public static void InsertVisitor()
       {
            HttpContext context=HttpContext.Current;
            if (context.Session["VisitorRecord"] == null)
            {
                VisitorRecord visitor = new VisitorRecord();
                visitor.IP = context.Request.UserHostAddress;
                visitor.OS = context.Request.Browser.Platform;
                visitor.Browser = context.Request.Browser.Browser;
                visitor.Time = DateTime.Now;
                if (context.Request.UrlReferrer != null)
                {
                    visitor.Referer = context.Request.UrlReferrer.ToString();
                }
                else
                {
                    visitor.Referer = string.Empty;
                }

                visitor.Target = context.Request.RawUrl;
                DbProvider.Instance().InsertVisitorRecord(visitor);
                context.Session["VisitorRecord"] = true;
            }
       }

       public static string CheckCode
       {
           get
           {
               return HttpContext.Current.Session["CheckCode"].ToString();
           }
       }

       public static DateTime FloodControl
       {
           get
           {
               if (HttpContext.Current.Session["FloodControl"] == null)
               {
                   return DateTime.MinValue;
               }
               return Convert.ToDateTime(HttpContext.Current.Session["FloodControl"].ToString());
           }
           set
           {
               HttpContext.Current.Session["FloodControl"] = DateTime.Now;
           }
       }

       public static DateTime GBookFloodControl
       {
           get
           {
               if (HttpContext.Current.Session["GBookFloodControl"] == null)
               {
                   return DateTime.MinValue;
               }
               return Convert.ToDateTime(HttpContext.Current.Session["GBookFloodControl"].ToString());
           }
           set
           {
               HttpContext.Current.Session["GBookFloodControl"] = DateTime.Now;
           }
       }

       public static Page CurrentPage
       {
           get
           {
               return (Page)HttpContext.Current.Handler;
           }
       }
       public static Page CurrentHandler
       {
           get
           {
               return (Page)HttpContext.Current.CurrentHandler;
           }
       }
       
    }
}
